package com.xmg.p2p.base.domain;

import java.math.BigDecimal;
import java.util.Date;

import lombok.Getter;
import lombok.Setter;

import com.xmg.p2p.base.util.BidConst;
import com.xmg.p2p.base.util.MD5;

/**
 * 用户对应的账户信息
 * 
 * 
 */
@Setter
@Getter 
public class Account extends BaseDomain {

	private int version;	// 版本号：乐观锁的控制
	private String tradePassword; // 交易密码
	private BigDecimal usableAmount = BidConst.ZERO; // 账户可用金额
	private BigDecimal freezedAmount = BidConst.ZERO; // 账户冻结金额
	private BigDecimal unReceiveInterest = BidConst.ZERO;// 账户待收利息
	private BigDecimal unReceivePrincipal = BidConst.ZERO;// 账户待收本金
	private BigDecimal unReturnAmount = BidConst.ZERO; // 账户待还金额
	private BigDecimal remainBorrowLimit = BidConst.INIT_BORROW_LIMIT; // 账户剩余授信额度
	private BigDecimal borrowLimit = BidConst.INIT_BORROW_LIMIT; // 账户授信额度
	private Date endloginTime;		// 最后一次登录的时间
	private String verify;

	public Date getEndloginTime() {
		return endloginTime;
	}

	public void setEndloginTime(Date endloginTime) {
		this.endloginTime = endloginTime;
	}

	public String getVerify(){
        return MD5.encode((this.id+" "+this.usableAmount.hashCode()+""+this.freezedAmount.hashCode()));
	}
	// 防止恶意篡改
	public boolean getIsValidate(){
		return MD5.encode((this.id+" "+this.usableAmount.hashCode()+""+this.freezedAmount.hashCode())).equals(this.verify);
	}
	
	
	public BigDecimal getTotalAmount(){
		return usableAmount.add(this.freezedAmount).add(this.unReceivePrincipal);
	}

	@Override
	public String toString() {
		return "Account{" +
				"version=" + version +
				", tradePassword='" + tradePassword + '\'' +
				", usableAmount=" + usableAmount +
				", freezedAmount=" + freezedAmount +
				", unReceiveInterest=" + unReceiveInterest +
				", unReceivePrincipal=" + unReceivePrincipal +
				", unReturnAmount=" + unReturnAmount +
				", remainBorrowLimit=" + remainBorrowLimit +
				", borrowLimit=" + borrowLimit +
				", endloginTime=" + endloginTime +
				", verify='" + verify + '\'' +
				'}';
	}
}
